﻿Imports System.Data.SqlClient

Public Class FrmPresentDataEntry

    Dim DSNEvent As DataSet
    Dim currentselectedtab As String
    Dim DSNPatient As DataSet
    Dim DSNInvestigation As DataSet
    Dim DSNHistory As DataSet
    Dim DSNHistology As DataSet
    Dim DSNTxRecommendation As DataSet
    Dim gv_isedit As String 'added by cherwei to insert, can be remove

    Dim is_on_loading As Boolean = False
    Dim GLB_startTime As DateTime

    Dim GLB_editedList As New ArrayList

    Dim GLB_init As Integer = 0

    Private Sub frmProgramma_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MessageBox.Show("Are you sur to close this application?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Dim SqlConn As SqlConnection = New SqlConnection(GV_CONNETION)
            Dim myCommand As SqlCommand = New SqlCommand("update [Event] set isOpened = 0", SqlConn)
            SqlConn.Open()
            myCommand.ExecuteNonQuery()
            SqlConn.Close()
        Else
            e.Cancel = True
        End If
    End Sub

    Private Sub FrmPresentDataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        is_on_loading = True
        If (Not Me.hasAnyUpdate) Then
            Me.Button2.BackColor = Color.Pink
        End If

        Me.entryModeEntered = False
        Me.Button2.BackColor = Color.Pink
        GV_SELECTED_DATAENTRY_MODE = "PRESENTATION"

        Dim NextFriday As Date

        If Now.DayOfWeek = DayOfWeek.Friday Then
            NextFriday = Now
        Else : NextFriday = GetNext(DayOfWeek.Friday)
        End If

        ListPresentationPatients(NextFriday)

        Dim testDate As Date = Date.Now

        Me.btbPresentDate.Value = nextDOW(DayOfWeek.Friday, testDate)
        'Console.Write(Me.btbPresentDate.Text)


        Me.LoadCT()
        Me.LoadCXR()
        Me.LoadBone()
        Me.LoadFamilyHistory()
        Me.LoadMenstrualStatus()

        Me.LoadExtChestWall()
        Me.LoadClinAxillaryLN()
        Me.LoadTypeBiopsy()
        Me.LoadHistoDx()
        Me.LoadTypeSurg()
        Me.LoadReconstruction()
        Me.LoadHistoType()
        Me.LoadHistoGrade()
        Me.LoadDCIS()
        Me.LoadLymhovascular()
        Me.LoadMargin_invasive()
        Me.LoadMarginDCIS()
        Me.LoadRadialMargin()
        Me.LoadSentinel_LN()
        Me.LoadSentinelLNPolarity()
        Me.LoadER_Status()
        Me.LoadPR_Status()
        Me.LoadErbB2()
        Me.LoadN_Status()
        Me.LoadM_Status()
        Me.LoadcT_Status()

        Me.LoadDoctor()
        Me.LoadCaseType()
        Me.LoadLaterality()


        Me.LoadBTB_Recommend()


        Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
        CNnwind.Open()
        Dim command As SqlCommand = CNnwind.CreateCommand()
        command.CommandText = "select distinct COUNT(Event_ID) AS eventCount from [event] where date_tb = '" + Me.btbPresentDate.Value.ToString("yyyy-MM-dd") + "' and status = 'A' "
        Dim reader As SqlDataReader = command.ExecuteReader()
        Dim eventCount As Integer = 0
        If reader.Read Then
            eventCount = Convert.ToInt16(reader.GetValue(0).ToString)
        End If
        CNnwind.Close()


        For index As Integer = 0 To eventCount
            Dim values As Integer = index + 1
            Me.presentOrder.Items.Add(Convert.ToString(values))
        Next

    End Sub

    Dim parentnode As TreeNode

    
    Function GetNext(ByVal d As DayOfWeek, Optional ByVal StartDate As Date = Nothing) As Date
        If StartDate = DateTime.MinValue Then StartDate = Now
        For p As Integer = 1 To 7
            If StartDate.AddDays(p).DayOfWeek = d Then Return StartDate.AddDays(p)
        Next
    End Function

    Private Sub ListPresentationPatients(ByVal btbDate As Date)


        Dim DSNWind As DataSet
        Dim CNnwind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select ptNRIC, ptName, Convert(date,date_tb) as date_tb, event.event_id, [status], " +
                                                    "case when indexRanking is null then convert(int, 99) else indexRanking end as orders " +
                                                    "from [event] inner join Patients on [event].Pt_id1 = Patients.Pt_id1 where date_tb = '" + btbDate.ToString("yyyy-MM-dd") + "' and [status] = 'A' order by orders asc, ptNRIC ",
                                                    CNnwind)

        DSNWind = New DataSet()
        CNnwind.Open()
        DSNWind.Clear()
        DAEvent.Fill(DSNWind, "dtEvent")

        CNnwind.Close()

        Try
            Me.TreeView1.Nodes.Clear()
        Catch ex As Exception

        End Try

        Dim vColor As String
        Dim vTreeColor As Color

        Dim i, n As Integer
        Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = DSNWind.Tables("dtEvent")

        Dim index As Integer = 1
        For Each parentrow In ParentTable.Rows

            Dim parentnodeStatuts As TreeNode
            parentnode = New TreeNode("[" + Convert.ToString(index) + "] " + ":   " + parentrow.Item(1) + " - (" + parentrow.Item(3) + ")")
            parentnodeStatuts = New TreeNode(parentrow.Item(4))
            TreeView1.Nodes.Add(parentnode)

            '+ parentrow.Item(0)
            'assign parentnode to tabpages
            'TabControl1.TabPages.Add(parentnode.Name)

            If parentrow("Status") = "P" Then
                vTreeColor = Color.Orange
            Else
                vTreeColor = Color.Black
            End If
            parentnode.ForeColor = vTreeColor
            ''''populate child'''''
            '''''''''''''''''''''''
            index = index + 1
        Next parentrow
        TreeView1.ExpandAll()


        For Each childNodeLevel1 As TreeNode In Me.TreeView1.Nodes
            Dim tmp As String = childNodeLevel1.Text
            Dim TestArray() As String = Split(tmp, "(")
            Dim TestArray2() As String = Split(TestArray(1), ")")
            Dim tmp_EVENTID As String = TestArray2(0)

            For Each editedEvent As String In Me.GLB_editedList
                If tmp_EVENTID = editedEvent Then
                    childNodeLevel1.ForeColor = Color.Green
                End If
            Next
        Next

    End Sub



    Dim hasAnyUpdate As Boolean = False
    Dim previsouSelectNode As TreeNode


    Dim prevSelectedEventID As String
    Private Sub TreeView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.NodeMouseDoubleClick

        Me.changeEventToEditable(prevSelectedEventID)
        Dim tmp As String = TreeView1.SelectedNode.Text
        Dim TestArray() As String = Split(tmp, "(")
        Dim TestArray2() As String = Split(TestArray(1), ")")
        GV_SELECTED_EVENTID = TestArray2(0)
        Dim isRecordOpened As Boolean = isEventOpened(GV_SELECTED_EVENTID)

        If Not isRecordOpened Then
            is_on_loading = True
            If TreeView1.Nodes.Count = 0 Then
                MsgBox("Please add new event.")
                Exit Sub
            End If

            Dim notSaveStatus As Boolean = False


            If (Me.hasAnyUpdate) Then
                Dim answer As DialogResult
                answer = MessageBox.Show("Save records?", "Yes/no sample", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If answer = vbYes Then
                    Me.changeEventToEditable(prevSelectedEventID)
                    saveAllRecords(prevSelectedEventID)
                End If
            End If


            Me.Button2.BackColor = Color.Pink
            Me.Button2.Text = "Save All"



            'Added by cherwei to check for lock status and disallow adding new data if locked
            Dim vEventIDtemp As String
            vEventIDtemp = ""



            Try
                'previsouSelectNode = TreeView1.SelectedNode
                'Dim tmp As String = TreeView1.SelectedNode.Text
                'Dim TestArray() As String = Split(tmp, "(")
                'Dim TestArray2() As String = Split(TestArray(1), ")")
                'GV_SELECTED_EVENTID = TestArray2(0)
                'MsgBox(GV_SELECTED_EVENTID)

                'selectedPatientIC.Text = getPatientIC(GV_SELECTED_EVENTID)
                'selectedPatName.Text = getPatientName(GV_SELECTED_EVENTID)
                'selectedPatAge.Text = "Age:" + getPatientAge(GV_SELECTED_EVENTID)


                ' TreeView1.SelectedNode.ForeColor = Color.Green
                'TreeView1.SelectedNode.ForeColor = Color.AliceBlue
                If Not notSaveStatus Then
                    Label42.Text = getPatientName(GV_SELECTED_EVENTID) + " / " + getPatientIC(GV_SELECTED_EVENTID) + " / " + "Age:" + getPatientAge(GV_SELECTED_EVENTID)
                    'saveAllRecords()
                    Dim recordOpen As Boolean = isEventOpened(GV_SELECTED_EVENTID)
                    If Not recordOpen Then

                        Me.displayPatientData(GV_SELECTED_EVENTID)
                        Me.changeInputToEditable()
                        prevSelectedEventID = GV_SELECTED_EVENTID
                        Me.TabPage5.Text = GV_SELECTED_EVENTID
                        'Me.entryModeEntered = False
                    Else
                        MsgBox("Record has been opened, cannot edit.")
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Source)
            End Try
        Else
            MsgBox("Record opened, cannot edit")
            Me.displayPatientData(GV_SELECTED_EVENTID)
            Label42.Text = getPatientName(GV_SELECTED_EVENTID) + " / " + getPatientIC(GV_SELECTED_EVENTID) + " / " + "Age:" + getPatientAge(GV_SELECTED_EVENTID)
            Me.TabPage5.Text = GV_SELECTED_EVENTID
            Me.changeInputToViewOnly()
        End If

    End Sub

    Private Sub saveAllRecords2()
        'MsgBox("All records saved")
        changeEventToEditable(GV_SELECTED_EVENTID)
        Me.GLB_init = Me.GLB_init + 1
    End Sub

    Private Sub changeInputToViewOnly()
        btnEventSave.Enabled = False
        btnHisology2.Enabled = False
        btnHistologySave.Enabled = False
        btnHistorySave.Enabled = False
        btnInvest2.Enabled = False
        btnInvSave.Enabled = False
        btnMedHis2.Enabled = False
        btnTxRec2.Enabled = False
        btnTxRecSave.Enabled = False
        cboxLocalRec.Enabled = False
        cboxMarginDCIS.Enabled = False
        CboxMeta.Enabled = False
        CboxMetasEvent.Enabled = False
        cboxNeoadjuvant.Enabled = False
        cboxSystemic.Enabled = False
        cbxBone.Enabled = False
        cbxCaseType.Enabled = False
        cbxClinAxillaryLN.Enabled = False
        cbxCT.Enabled = False
        cbxCXR.Enabled = False
        cbxDCIS.Enabled = False
        cbxDoctor.Enabled = False
        cbxExtChestWall.Enabled = False
        cbxHistoDx.Enabled = False
        cbxHistoGrade.Enabled = False
        cbxHistory.Enabled = False
        cbxHistoType.Enabled = False
        cbxLaterality.Enabled = False
        cbxLymhovascular.Enabled = False
        cbxMargin_invasive.Enabled = False
        cbxradialMargin.Enabled = False
        cbxReconstruction.Enabled = False
        cbxSentinel_LN.Enabled = False
        cbxSentinelLNPolarity.Enabled = False
        cbxStatus.Enabled = False
        cbxTypeBiopsy.Enabled = False
        cbxTypeSurg.Enabled = False
        dtDateBiopsy.Enabled = False
        DtPrisurg.Enabled = False
        Lbl_EnBy.Enabled = False
        lbl_entereddatetime.Enabled = False
        Lbl_LockBy.Enabled = False
        lbl_LockedDateTime.Enabled = False
        lbl_updateddatetime.Enabled = False
        Lbl_UpdBy.Enabled = False
        RichTextNotes.Enabled = False
        txtDeepMargin.Enabled = False
        txtHisto_TumourSize.Enabled = False
        txtHistoNotes.Enabled = False
        txtPhysicalNotes.Enabled = False
        txtRadialMargin.Enabled = False
        txtTotal_Ax_LN_Found.Enabled = False
        txtTotal_Ax_LN_Postive.Enabled = False
        txtTumourSize.Enabled = False
    End Sub

    Private Sub changeInputToEditable()
        btnEventSave.Enabled = True
        btnHisology2.Enabled = True
        btnHistologySave.Enabled = True
        btnHistorySave.Enabled = True
        btnInvest2.Enabled = True
        btnInvSave.Enabled = True
        btnMedHis2.Enabled = True
        btnTxRec2.Enabled = True
        btnTxRecSave.Enabled = True
        cboxLocalRec.Enabled = True
        cboxMarginDCIS.Enabled = True
        CboxMeta.Enabled = True
        CboxMetasEvent.Enabled = True
        cboxNeoadjuvant.Enabled = True
        cboxSystemic.Enabled = True
        cbxBone.Enabled = True
        cbxCaseType.Enabled = True
        cbxClinAxillaryLN.Enabled = True
        cbxCT.Enabled = True
        cbxCXR.Enabled = True
        cbxDCIS.Enabled = True
        cbxDoctor.Enabled = True
        cbxExtChestWall.Enabled = True
        cbxHistoDx.Enabled = True
        cbxHistoGrade.Enabled = True
        cbxHistory.Enabled = True
        cbxHistoType.Enabled = True
        cbxLaterality.Enabled = True
        cbxLymhovascular.Enabled = True
        cbxMargin_invasive.Enabled = True
        cbxradialMargin.Enabled = True
        cbxReconstruction.Enabled = True
        cbxSentinel_LN.Enabled = True
        cbxSentinelLNPolarity.Enabled = True
        cbxStatus.Enabled = True
        cbxTypeBiopsy.Enabled = True
        cbxTypeSurg.Enabled = True
        dtDateBiopsy.Enabled = True
        DtPrisurg.Enabled = True
        Lbl_EnBy.Enabled = True
        lbl_entereddatetime.Enabled = True
        Lbl_LockBy.Enabled = True
        lbl_LockedDateTime.Enabled = True
        lbl_updateddatetime.Enabled = True
        Lbl_UpdBy.Enabled = True
        RichTextNotes.Enabled = True
        txtDeepMargin.Enabled = True
        txtHisto_TumourSize.Enabled = True
        txtHistoNotes.Enabled = True
        txtPhysicalNotes.Enabled = True
        txtRadialMargin.Enabled = True
        txtTotal_Ax_LN_Found.Enabled = True
        txtTotal_Ax_LN_Postive.Enabled = True
        txtTumourSize.Enabled = True
    End Sub

    Private Sub saveAllRecords(ByVal selected_EventID As String)
        MsgBox("SAVING " + selected_EventID)
        'check if event is locked, enable/disable save button
        If Trim(selected_EventID) = "" Then
            'btnSave.Enabled = False
        Else
            'btnSave.Enabled = True
        End If


        'Perform the save functions
        'save function for event
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent3", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@indexRanking", SqlDbType.Int)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        'check n retrieve current eventid on the form, if eventid is empty, gv_isedit = false else gv_isedit = true
        'If Trim(lblEvent.Text).IndexOf("E") = -1 Then
        'gv_isedit = False
        'Else
        'gv_isedit = True
        'End If
        If (GV_CUR_PATID Is Nothing) Then
            GV_CUR_PATID = ""
        End If


        myCommand.Parameters("@Event_ID").Value = selected_EventID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(cbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(cbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(CboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(CboxMetasEvent.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        Try
            myCommand.Parameters("@indexRanking").Value = Convert.ToInt16(Me.presentOrder.Text)
        Catch ex As Exception
            myCommand.Parameters("@indexRanking").Value = 99
        End Try


        myCommand.ExecuteNonQuery()




        ' perform the save procedures to other tables 
        'save function for investigation
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertInvestigation2", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
        myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = selected_EventID
        myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
        myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
        myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
        myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        myCommand.ExecuteNonQuery()



        'save function for tx recommendation details
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertTxRecommendation2", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
        myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
        myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
        myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
        myCommand.Parameters("@Event_ID").Value = selected_EventID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
        myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
        myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
        myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
        myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
        myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
        myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
        myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
        myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        myCommand.ExecuteNonQuery()


        'save history table
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertHistory2", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)


        myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = selected_EventID
        myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
        myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        myCommand.ExecuteNonQuery()


        'save histology table
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistology2", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
            myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
            myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
            myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
            myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_2", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
            myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = selected_EventID
            myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
            myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
            myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
            myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
            myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
            myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
            myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
            myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
            myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
            myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
            myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
            myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
            myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
            myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
            myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
            myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
            myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
            myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
            myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
            myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
            myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
            myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
            myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
            myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
            myCommand.Parameters("@SLN_2").Value = ""
            myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
            myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
            myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
            myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
            myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
            myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
            myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
            myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            myCommand.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try


        MsgBox("All records saved")
        changeEventToEditable(selected_EventID)
        Me.GLB_init = Me.GLB_init + 1
        is_on_loading = False

        GLB_editedList.Add(selected_EventID)

        ListPresentationPatients(Me.btbPresentDate.Value)
       




    End Sub

    Private Sub TreeView1_Patientselected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.NodeMouseClick

    End Sub


    Private Function getPatientIC(ByVal currentEventID As String)
        Dim ptNRIC As String
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select ptNRIC from Patients inner join [event] on Patients.pt_id1 =  [event].pt_id1 where Event_ID ='" & currentEventID & "'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

        Dim currentPt_id As String

        'Load from event table
        Try
            DSNEvent = New DataSet()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            ptNRIC = DSNEvent.Tables("dtEvent").Rows(0).Item("ptNRIC")
            CNnWind.Close()

        Catch a As Exception
            Exit Function
        End Try

        Return ptNRIC
    End Function

    Private Function getPatientAge(ByVal currentEventID As String)
        Dim patAge As String
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select (year(GetDate()) - year(Patients.PtBirthDate)) as [age]  from Patients inner join [event] on Patients.pt_id1 =  [event].pt_id1 where Event_ID ='" & currentEventID & "'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

        Dim currentPt_id As String

        'Load from event table
        Try
            DSNEvent = New DataSet()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            patAge = DSNEvent.Tables("dtEvent").Rows(0).Item("age")
            CNnWind.Close()

        Catch a As Exception
            Exit Function
        End Try

        Return patAge
    End Function

    Private Function getPatientName(ByVal currentEventID As String)
        Dim Name As String
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select PtName  from Patients inner join [event] on Patients.pt_id1 =  [event].pt_id1 where Event_ID ='" & currentEventID & "'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

        Dim currentPt_id As String

        'Load from event table
        Try
            DSNEvent = New DataSet()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            Name = DSNEvent.Tables("dtEvent").Rows(0).Item("PtName")
            CNnWind.Close()

        Catch a As Exception
            Exit Function
        End Try

        Dim result As String = ""
        Try
            result = Name.Substring(0, 20)
        Catch ex As Exception
            result = Name
        End Try
        Return result
    End Function

    Private Function isEventOpened(ByVal currentEventID As String) As Boolean
        Dim result As Boolean = False
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select isOpened from Event where Event_ID = '" & currentEventID & "'", CNnWind)

        Try
            DSNEvent = New DataSet()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            CNnWind.Close()

            Dim eventTable As DataTable = DSNEvent.Tables("dtEvent")

            Dim drCurrent As DataRow
            For Each drCurrent In eventTable.Rows
                If String.IsNullOrEmpty(drCurrent("isOpened"))Then  'It is closed
                    result = False
                ElseIf drCurrent("isOpened") = 0 Then 'It is closed
                    result = False
                Else
                    result = True
                End If
            Next

        Catch a As Exception
            Exit Function
        End Try
        Return result
    End Function


    Private Sub changeEventToEditing(ByVal currentEventID As String)
        Try
            Dim SqlConn As SqlConnection = New SqlConnection(GV_CONNETION)
            Dim myCommand As SqlCommand = New SqlCommand("update Event set isOpened = 1 where Event_ID = '" & currentEventID & "'", SqlConn)
            SqlConn.Open()
            myCommand.ExecuteNonQuery()
            SqlConn.Close()
        Catch a As Exception
            Exit Sub
        End Try
    End Sub


    Private Sub changeEventToEditable(ByVal currentEventID As String)
        Try
            Dim SqlConn As SqlConnection = New SqlConnection(GV_CONNETION)
            Dim myCommand As SqlCommand = New SqlCommand("update Event set isOpened = 0 where Event_ID = '" & currentEventID & "'", SqlConn)
            SqlConn.Open()
            myCommand.ExecuteNonQuery()
            SqlConn.Close()
        Catch a As Exception
            Exit Sub
        End Try
    End Sub


    Private Sub displayPatientData(ByVal currentEventID As String)
        If String.IsNullOrEmpty(GV_SELECTED_EVENTID) Then
            Me.hasAnyUpdate = False
        End If

        If (Not Me.hasAnyUpdate) Then
            Me.Button2.BackColor = Color.Pink
        End If


        Dim eventOpened As Boolean = isEventOpened(currentEventID)
        hasAnyUpdate = False
        'If Not eventOpened Then
        changeEventToEditing(currentEventID)

        'currentDS.Tables("dtInvestigation").Rows(0).Item(
        'Load from investigation table
        'currentEventID = "E023"
        Dim patientName As String
        Dim patientNRIC As String
        Dim patientAge As String
        Dim inc As Integer

        Dim count As Integer

        'if currenteventID is empty, disableallfields and exit sub
        If (currentEventID = "") Then
            Exit Sub
        Else
        End If



        Dim tmp As String = TreeView1.SelectedNode.Text
        Dim TestArray() As String = Split(tmp, "]")
        Dim TestArray2() As String = Split(TestArray(0), "[")
        Dim indexRank As String = TestArray2(1)

        presentOrder.SelectedItem = indexRank


            'Load from event table
            Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
            'Dim datetimepickertext As String = DateTimePicker1.Text.ToString()

            'Dim currentDOBtext As String = DOB.Text.ToString
            'Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where convert(varchar, date_tb,103) = '" & currentDOBtext & "' and status <> 'D'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where [event].Event_ID = '" & currentEventID & "' and status <> 'D'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

            Dim currentPt_id As String

            'Load from event table
            Try
                DSNEvent = New DataSet()
                CNnWind.Open()
                DAEvent.Fill(DSNEvent, "dtEvent")
                CNnWind.Close()

                'reset event counter if there are records
                If DSNEvent.Tables("dtEvent").Rows.Count >= 1 Then
                    inc = 0
                End If

                'load from event table
                currentEventID = DSNEvent.Tables("dtEvent").Rows(inc).Item("Event_ID")
                currentPt_id = DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")

                'lblEvent.Text = currentEventID
                GV_SELECTED_EVENTID = currentEventID
                DOB.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb"))
                DateTimePicker1.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn"))
                cbxDoctor.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc"))
                cbxCaseType.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type"))
                cbxLaterality.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen"))
                CboxMeta.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status"))
                GV_CUR_PATID = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1"))

            'presentOrder.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("orders")), "NULL", DSNEvent.Tables("dtEvent").Rows(inc).Item("orders"))

                If (currentselectedtab = "TabPage: {Event}") Then

                    Lbl_EnBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy"))
                    lbl_entereddatetime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredTime"))
                    Lbl_UpdBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy"))
                    lbl_updateddatetime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedTime"))
                    Lbl_LockBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy"))
                    lbl_LockedDateTime.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedTime")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedTime"))

                End If

                Lbl_EnBy.Visible = True
                Lbl_UpdBy.Visible = True
                Lbl_LockBy.Visible = True
                lbl_entereddatetime.Visible = True
                lbl_updateddatetime.Visible = True
                lbl_LockedDateTime.Visible = True


            Catch a As Exception
                Exit Sub
            End Try

            Dim currenteventstatus As String
            currenteventstatus = DSNEvent.Tables("dtEvent").Rows(inc).Item("Status")
            If currenteventstatus = "P" Then
                DOB.Enabled = False
                DateTimePicker1.Enabled = False
                cbxDoctor.Enabled = False
                cbxCaseType.Enabled = False
                cbxLaterality.Enabled = False
                CboxMeta.Enabled = False
                CboxMetasEvent.Enabled = False
                'btnSave.Enabled = False
            Else
                DOB.Enabled = True
                DateTimePicker1.Enabled = True
                cbxDoctor.Enabled = True
                cbxCaseType.Enabled = True
                cbxLaterality.Enabled = True
                CboxMeta.Enabled = True
                CboxMetasEvent.Enabled = True
                'btnSave.Enabled = True
            End If

            LoadMetasynchronous()
            CboxMetasEvent.SelectedValue = DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasynchronous")

            'Load from patient table, retrieve name and nric
            Dim DAPatient As New SqlClient.SqlDataAdapter("select distinct * from patients where Pt_id1 = '" & currentPt_id & "'", CNnWind)
            DSNPatient = New DataSet()
            CNnWind.Open()
            DAPatient.Fill(DSNPatient, "dtPatient")
            CNnWind.Close()

            count = DSNPatient.Tables("dtPatient").Rows.Count
            If (count > 0) Then
                'PatName.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtName")
                'PatNRIC.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtNRIC")
                'lblAge.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtAge")
            End If





            'Load from investigation table
            Dim DAInvestigation As New SqlClient.SqlDataAdapter("select * from Investigation where event_id = '" & currentEventID & "' and status <> 'D'", CNnWind)
            DSNInvestigation = New DataSet()
            CNnWind.Open()
            DAInvestigation.Fill(DSNInvestigation, "dtInvestigation")
            CNnWind.Close()

            Try
                count = DSNInvestigation.Tables("dtInvestigation").Rows.Count
            Catch ex As Exception
                cbxCXR.Enabled = False
                cbxCT.Enabled = False
                cbxBone.Enabled = False
                RichTextNotes.Enabled = False
                GV_SELECTED_INVESTID = ""
            End Try
            If (count > 0) Then
                GV_SELECTED_INVESTID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
                cbxCXR.SelectedValue = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CXR")
                cbxCT.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CT")
                cbxBone.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("BoneScan")
                RichTextNotes.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Notes")
                cbxCXR.Enabled = True
                cbxCT.Enabled = True
                cbxBone.Enabled = True
                RichTextNotes.Enabled = True

                If (currentselectedtab = "TabPage: {Investigation}") Then

                    Lbl_EnBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredBy"))
                    lbl_entereddatetime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("EnteredTime"))
                    Lbl_UpdBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedBy"))
                    lbl_updateddatetime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("UpdatedTime"))
                    Lbl_LockBy.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedBy")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedBy"))
                    lbl_LockedDateTime.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedTime")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("LockedTime"))
                End If

            Else
                cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
                cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
                cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
                RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
                cbxCXR.Enabled = False
                cbxCT.Enabled = False
                cbxBone.Enabled = False
                RichTextNotes.Enabled = False

            End If

            If currenteventstatus = "P" Then 'P:lock so disable all fields
                cbxCXR.Enabled = False
                cbxCT.Enabled = False
                cbxBone.Enabled = False
                RichTextNotes.Enabled = False

                'Disable all buttons
                btnHisology2.Enabled = False
                btnHistologySave.Enabled = False
                btnEventSave.Enabled = False
                btnInvest2.Enabled = False
                btnInvSave.Enabled = False
                btnMedHis2.Enabled = False
                btnHistorySave.Enabled = False
                btnTxRec2.Enabled = False
                btnTxRecSave.Enabled = False
            ElseIf (count = 0) Then
                cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
                cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
                cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
                RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
                cbxCXR.Enabled = False
                cbxCT.Enabled = False
                cbxBone.Enabled = False
                RichTextNotes.Enabled = False
            Else
                cbxCXR.Enabled = True
                cbxCT.Enabled = True
                cbxBone.Enabled = True
                RichTextNotes.Enabled = True

                'Enable all buttons
                btnHisology2.Enabled = True
                btnHistologySave.Enabled = True
                btnEventSave.Enabled = True
                btnInvest2.Enabled = True
                btnInvSave.Enabled = True
                btnMedHis2.Enabled = True
                btnHistorySave.Enabled = True
                btnTxRec2.Enabled = True
                btnTxRecSave.Enabled = True

            End If


            'Load from history table
            Dim DAHistory As New SqlClient.SqlDataAdapter("select * from History where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
            DSNHistory = New DataSet()
            CNnWind.Open()
            DAHistory.Fill(DSNHistory, "dtHistory")
            CNnWind.Close()
            count = DSNHistory.Tables("dtHistory").Rows.Count
            If (count > 0) Then
                GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
                cbxHistory.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("FamilyHistory")
                cbxStatus.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("Menstrual")
                cbxHistory.Enabled = True
                cbxStatus.Enabled = True


                If (currentselectedtab = "TabPage: {History}") Then
                    Lbl_EnBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredBy"))
                    lbl_entereddatetime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("EnteredTime"))
                    Lbl_UpdBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedBy"))
                    lbl_updateddatetime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("UpdatedTime"))
                    Lbl_LockBy.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("LockedBy")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("LockedBy"))
                    lbl_LockedDateTime.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("LockedTime")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("LockedTime"))
                End If

            Else
                cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
                cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

                cbxHistory.Enabled = False
                cbxStatus.Enabled = False
                GV_SELECTED_HISTORYID = ""
            End If


            If currenteventstatus = "P" Then
                cbxHistory.Enabled = False
                cbxStatus.Enabled = False
            ElseIf (count = 0) Then
                cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
                cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

                cbxHistory.Enabled = False
                cbxStatus.Enabled = False
                GV_SELECTED_HISTORYID = ""
            Else

                cbxHistory.Enabled = True
                cbxStatus.Enabled = True
            End If




            'Load from histology table

            Dim DAHistology As New SqlClient.SqlDataAdapter("select * from Histology where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
            DSNHistology = New DataSet()
            CNnWind.Open()
            DAHistology.Fill(DSNHistology, "dtHistology")
            CNnWind.Close()

            count = DSNHistology.Tables("dtHistology").Rows.Count
            If (count > 0) Then
                GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
                txtTumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size"))
                cbxExtChestWall.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw"))
                cbxClinAxillaryLN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln"))
                cbxTypeBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
                dtDateBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
                cbxHistoDx.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
                DtPrisurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
                cbxTypeSurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
                cbxReconstruction.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
                cboxNeoadjuvant.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
                cboxLocalRec.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
                cboxSystemic.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
                txtPhysicalNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
                txtHistoNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
                txtHisto_TumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
                cbxHistoType.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
                cbxHistoGrade.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
                cbxDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
                cbxLymhovascular.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
                cbxMargin_invasive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
                cboxMarginDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
                cbxradialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
                txtRadialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
                txtDeepMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
                cbxSentinel_LN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
                cbxSentinelLNPolarity.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2"))
                txtTotal_Ax_LN_Postive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
                txtTotal_Ax_LN_Found.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                cbxSide.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("side")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("side"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
                cbxPR_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
                cbxErbB2.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
                cbxcT_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
                cbxN_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6"))
                cbxM_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6"))


                If (currentselectedtab = "TabPage: {Histology}") Then
                    Lbl_EnBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredBy"))
                    lbl_entereddatetime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("EnteredTime"))
                    Lbl_UpdBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedBy"))
                    lbl_updateddatetime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("UpdatedTime"))
                    Lbl_LockBy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("LockedBy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("LockedBy"))
                    lbl_LockedDateTime.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("LockedTime")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("LockedTime"))

                End If

                txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
                cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
                cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
                cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
                dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
                cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
                DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
                cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
                cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
                cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
                cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
                cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
                txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
                txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
                txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
                cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
                cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
                cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
                cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
                cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
                cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
                cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
                txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
                txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
                cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
                cbxSentinelLNPolarity.Enabled = True
                txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
                cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
                cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
                cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
                cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
                cbxM_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

                cbxSide.Enabled = True

            Else
                txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
                cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
                cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
                cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
                dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
                cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
                DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
                cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
                cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
                cboxNeoadjuvant.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
                cboxLocalRec.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
                cboxSystemic.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
                txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
                txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
                txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
                cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
                cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
                cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
                cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
                cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
                cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
                cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
                txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
                txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
                cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
                'cbxSentinelLNPolarity.Text = ""
                txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
                cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
                cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
                cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
                cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
                cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
                cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

                cbxSide.Text = ""

                txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
                cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
                cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
                cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
                dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
                cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
                DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
                cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
                cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
                cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
                cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
                cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
                txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
                txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
                txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
                cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
                cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
                cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
                cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
                cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
                cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
                cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
                txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
                txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
                cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
                cbxSentinelLNPolarity.Enabled = False
                txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
                cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
                cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
                cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
                cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
                cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

                cbxSide.Enabled = False

                GV_SELECTED_HISTOLOGYID = ""
            End If

            If currenteventstatus = "P" Then 'P:lock so disable all fields
                cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
                cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
                cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
                txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
                cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
                cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
                cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
                dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
                cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
                DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
                cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
                cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
                cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
                cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
                cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
                txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
                txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
                txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
                cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
                cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
                cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
                cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
                cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
                cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
                cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
                txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
                txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
                cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
                cbxSentinelLNPolarity.Enabled = False
                txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
                cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
                cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
                cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
                cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
                cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

                cbxSide.Enabled = False

            ElseIf (count = 0) Then
                txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
                cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
                cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
                cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
                dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
                cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
                DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
                cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
                cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
                txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
                txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
                txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
                cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
                cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
                cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
                cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
                cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
                cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
                cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
                txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
                txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
                cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
                cbxSentinelLNPolarity.Text = ""
                dtDateBiopsy.Text = ""
                DtPrisurg.Text = ""
                txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
                cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
                cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
                cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
                cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
                cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
                cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

                cbxSide.Text = ""

                txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
                cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
                cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
                cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
                dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
                cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
                DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
                cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
                cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
                cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
                cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
                cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
                txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
                txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
                txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
                cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
                cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
                cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
                cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
                cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
                cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
                cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
                txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
                txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
                cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
                cbxSentinelLNPolarity.Enabled = False
                txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
                cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
                cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
                cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
                cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
                cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

                cbxSide.Enabled = False

                GV_SELECTED_HISTOLOGYID = ""
            Else
                cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
                cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
                cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
                txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
                cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
                cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
                cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
                dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
                cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
                DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
                cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
                cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
                cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
                cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
                cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
                txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
                txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
                txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
                cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
                cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
                cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
                cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
                cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
                cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
                cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
                txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
                txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
                cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
                cbxSentinelLNPolarity.Enabled = True
                txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
                txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

                'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
                cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
                cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
                cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
                cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
                cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
                cbxM_Status.Enabled = True

                cbxSide.Enabled = True
            End If

            'Load from TxRecommendation
            Dim DATxRecommendation As New SqlClient.SqlDataAdapter("select * from recom where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
            DSNTxRecommendation = New DataSet()
            CNnWind.Open()
            DATxRecommendation.Fill(DSNTxRecommendation, "dtTxRecommendation")
            CNnWind.Close()

            count = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
            If (count > 0) Then
                GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
                cbxBTBRecommend.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommendation")
                cboxChemo.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

                If (currentselectedtab = "TabPage: {TxRecommendation}") Then
                    Lbl_EnBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredBy"))
                    lbl_entereddatetime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("EnteredTime"))
                    Lbl_UpdBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedBy"))
                    lbl_updateddatetime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("UpdatedTime"))
                    Lbl_LockBy.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedBy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedBy"))
                    lbl_LockedDateTime.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedTime")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("LockedTime"))
                End If

                cbxBTBRecommend.Enabled = True
                cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Enabled = True
            Else
                cbxBTBRecommend.Text = ""
                cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

                cbxBTBRecommend.Enabled = False
                cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Enabled = False

                GV_SELECTED_TXID = ""
            End If

            If currenteventstatus = "P" Then
                cbxBTBRecommend.Enabled = False
                cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Enabled = False
            ElseIf (count = 0) Then
                cbxBTBRecommend.Text = ""
                cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

                cbxBTBRecommend.Enabled = False
                cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Enabled = False

                GV_SELECTED_TXID = ""
            Else
                cbxBTBRecommend.Enabled = True
                cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
                cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
                cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
                cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
                cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
                cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
                txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
                txtNotes.Enabled = True
            End If




            'Else
            'MsgBox("Event is being editing. Pls wait for it to complete first.")
            'End If
       
        Me.is_on_loading = False
    End Sub





    'start of dummy methods
    Private Sub LoadMetasynchronous()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("spGetMetasyn", SqlConnection1)
        sqlCmd.Parameters.Add("@Pt_ID1", SqlDbType.Int)
        sqlCmd.Parameters.Add("@Event_Id", SqlDbType.Char)
        sqlCmd.Parameters("@Pt_ID1").Value = GV_CUR_PATID
        sqlCmd.Parameters("@Event_Id").Value = GV_SELECTED_EVENTID
        sqlCmd.CommandType = CommandType.StoredProcedure
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("brst_screen", GetType(String)))
            list.Columns.Add(New DataColumn("Event_ID", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("brst_screen")), "", objReader("brst_screen"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Event_ID")), "", objReader("Event_ID"))
                i = i + 1
            Loop
            Me.CboxMetasEvent.DataSource = list
            Me.CboxMetasEvent.DisplayMember = "brst_screen"
            Me.CboxMetasEvent.ValueMember = "Event_ID"

        Catch e As Exception
            'MsgBox(e.Source & e.Message)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Function nextDOW(whDayOfWeek As DayOfWeek, _
                        Optional theDate As DateTime = Nothing) As DateTime
        'returns the next day of the week
        If theDate = Nothing Then theDate = DateTime.Now
        Dim d As DateTime = theDate.AddDays(whDayOfWeek - theDate.DayOfWeek)
        Return If(d <= theDate, d.AddDays(7), d)
    End Function












    Private Sub LoadPR_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 178", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxPR_Status.DataSource = list
            Me.cbxPR_Status.DisplayMember = "Code_desc"
            Me.cbxPR_Status.ValueMember = "Code"

        Catch e As Exception
            'MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoDx()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  118", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoDx.DataSource = list
            Me.cbxHistoDx.DisplayMember = "code_desc"
            Me.cbxHistoDx.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadTypeBiopsy()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  112", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeBiopsy.DataSource = list
            Me.cbxTypeBiopsy.DisplayMember = "code_desc"
            Me.cbxTypeBiopsy.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadER_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 173", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxER_Status.DataSource = list
            Me.cbxER_Status.DisplayMember = "Code_desc"
            Me.cbxER_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadSentinel_LN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  547", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinel_LN.DataSource = list
            Me.cbxSentinel_LN.DisplayMember = "Code_desc"
            Me.cbxSentinel_LN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadSentinelLNPolarity()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  548", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinelLNPolarity.DataSource = list
            Me.cbxSentinelLNPolarity.DisplayMember = "Code_desc"
            Me.cbxSentinelLNPolarity.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

    End Sub
    Private Sub LoadRadialMargin()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  165", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxradialMargin.DataSource = list
            Me.cbxradialMargin.DisplayMember = "Code_desc"
            Me.cbxradialMargin.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMarginDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  162", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cboxMarginDCIS.DataSource = list
            Me.cboxMarginDCIS.DisplayMember = "Code_desc"
            Me.cboxMarginDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMargin_invasive()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  159", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxMargin_invasive.DataSource = list
            Me.cbxMargin_invasive.DisplayMember = "Code_desc"
            Me.cbxMargin_invasive.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadLymhovascular()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  154", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxLymhovascular.DataSource = list
            Me.cbxLymhovascular.DisplayMember = "Code_desc"
            Me.cbxLymhovascular.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  260", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxDCIS.DataSource = list
            Me.cbxDCIS.DisplayMember = "Code_Desc"
            Me.cbxDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadcT_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 274", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxcT_Status.DataSource = list
            Me.cbxcT_Status.DisplayMember = "Code_desc"
            Me.cbxcT_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadTypeSurg()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  124", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeSurg.DataSource = list
            Me.cbxTypeSurg.DisplayMember = "Code_desc"
            Me.cbxTypeSurg.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoGrade()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  149", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoGrade.DataSource = list
            Me.cbxHistoGrade.DisplayMember = "Code_desc"
            Me.cbxHistoGrade.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadHistoType()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  132", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoType.DataSource = list
            Me.cbxHistoType.DisplayMember = "code_desc"
            Me.cbxHistoType.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadClinAxillaryLN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  107", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxClinAxillaryLN.DataSource = list
            Me.cbxClinAxillaryLN.DisplayMember = "code_desc"
            Me.cbxClinAxillaryLN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadExtChestWall()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  103", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxExtChestWall.DataSource = list
            Me.cbxExtChestWall.DisplayMember = "Code_Desc"
            Me.cbxExtChestWall.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadBTB_Recommend()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 306", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBTBRecommend.DataSource = list
            Me.cbxBTBRecommend.DisplayMember = "code_desc"
            Me.cbxBTBRecommend.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadFamilyHistory()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 2", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxHistory.DataSource = list
            Me.cbxHistory.DisplayMember = "code_desc"
            Me.cbxHistory.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMenstrualStatus()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 1", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxStatus.DataSource = list
            Me.cbxStatus.DisplayMember = "code_desc"
            Me.cbxStatus.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadCT()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  6", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxCT.DataSource = list
            Me.cbxCT.DisplayMember = "code_desc"
            Me.cbxCT.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadBone()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  8", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBone.DataSource = list
            Me.cbxBone.DisplayMember = "code_desc"
            Me.cbxBone.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadCXR()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  5", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxCXR.DataSource = list
            Me.cbxCXR.DisplayMember = "Code_desc"
            Me.cbxCXR.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadReconstruction()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  544", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxReconstruction.DataSource = list
            Me.cbxReconstruction.DisplayMember = "Code_desc"
            Me.cbxReconstruction.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub


    Private Sub LoadErbB2()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 183", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxErbB2.DataSource = list
            Me.cbxErbB2.DisplayMember = "Code_desc"
            Me.cbxErbB2.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub



    Private Sub LoadN_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 200", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxN_Status.DataSource = list
            Me.cbxN_Status.DisplayMember = "Code_desc"
            Me.cbxN_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub



    Private Sub LoadM_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 207", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxM_Status.DataSource = list
            Me.cbxM_Status.DisplayMember = "Code_desc"
            Me.cbxM_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub



    Private Sub LoadDoctor()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  83", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxDoctor.DataSource = list
            Me.cbxDoctor.DisplayMember = "code_desc"
            Me.cbxDoctor.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub



    Private Sub LoadCaseType()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 84", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxCaseType.DataSource = list
            Me.cbxCaseType.DisplayMember = "code_desc"
            Me.cbxCaseType.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub


    Private Sub LoadLaterality()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 9", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxLaterality.DataSource = list
            Me.cbxLaterality.DisplayMember = "code_desc"
            Me.cbxLaterality.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub


    'Button events
    Private Sub btnInvest2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvest2.Click

        GV_SELECTED_INVESTID = "0"

        'GV_SELECTED_EVENTID

        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAInvestigationTemp As New SqlClient.SqlDataAdapter("SELECT INV_MSG, EVENT_ID, PT_Id1, INV_ID, Status FROM INVESTIGATION where STATUS <> 'D' and EVENT_ID = '" & GV_SELECTED_EVENTID & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAInvestigationTemp.Fill(DSNWindTemp, "dtInvestigationTemp")
        Dim totalcount As Integer = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Duplicated INVESTIGATION record '" & DSNWindTemp.Tables(0).Rows(0)("INV_ID") & "' has been created before. You cannot proceed")
            Exit Sub
        End If

        FrmInvestigation.Close()
        FrmInvestigation.Show()
        FrmInvestigation.Focus()
        'FrmInvestigation.Button1_Click(sender, e)

        'btnInvest_Click(sender, e)
    End Sub

    Private Sub btnMedHis2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMedHis2.Click


        'GV_SELECTED_EVENTID


        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistoryTemp As New SqlClient.SqlDataAdapter("SELECT HISTORY_MSG, EVENT_ID, PT_Id1, HISTORY_ID, Status FROM HISTORY where STATUS <> 'D' and EVENT_ID = '" & GV_SELECTED_EVENTID & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistoryTemp.Fill(DSNWindTemp, "dtHistoryTemp")
        Dim totalcount As Integer = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing medical history for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")
            Exit Sub
        End If



        FrmHistory.Close()
        FrmHistory.Show()
        FrmHistory.Focus()
        'FrmHistory.btnAdd_Click(sender, e)
        'btnMedHis_Click(sender, e)
    End Sub


    Private Sub btnHisology2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHisology2.Click


        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DAHistologyTemp As New SqlClient.SqlDataAdapter("SELECT Histology_msg, EVENT_ID, PT_Id1, Histo_ID , Status FROM Histology where STATUS <> 'D' and EVENT_ID = '" & GV_SELECTED_EVENTID & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DAHistologyTemp.Fill(DSNWindTemp, "dtHistologyTemp")
        Dim totalcount As Integer = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

            Exit Sub
        End If

        FrmHistology.Close()
        FrmHistology.Show()
        FrmHistology.Focus()
        'FrmHistology.BtnAdd_Click(sender, e)
        'btnHisology_Click(sender, e)
    End Sub


    Private Sub btnTxRec2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxRec2.Click


        Dim CNnwind2 As New SqlClient.SqlConnection(GV_CONNETION)
        Dim DATxRecommendationTemp As New SqlClient.SqlDataAdapter("SELECT Tx_msg, EVENT_ID, PT_Id1, recom_id , Status FROM recom where  status <>'D' and EVENT_ID = '" & GV_SELECTED_EVENTID & "'", CNnwind2)
        Dim DSNWindTemp As DataSet
        DSNWindTemp = New DataSet()
        DATxRecommendationTemp.Fill(DSNWindTemp, "dtTxRecommendationTemp")
        Dim totalcount As Integer = DSNWindTemp.Tables(0).Rows.Count

        If (totalcount > 0) Then
            MsgBox("Please add new event. There is alreadly an existing histology for selected event '" & DSNWindTemp.Tables(0).Rows(0)("EVENT_ID") & "'")

            Exit Sub
        End If

        FrmTxRecommendation.Close()
        FrmTxRecommendation.Show()
        FrmTxRecommendation.Focus()
        'FrmHistology.BtnAdd_Click(sender, e)
        'btnHisology_Click(sender, e)
    End Sub


    Private Sub btnInvSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvSave.Click
        SaveInvestigation()
    End Sub


    Private Sub btnEventSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEventSave.Click
        SavePatientEvent()

    End Sub


    Private Sub btnHistorySave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHistorySave.Click
        SavePatientHistory()
    End Sub


    Private Sub btnHistologySave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHistologySave.Click
        SaveHistology()
    End Sub

    Private Sub btnTxRecSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTxRecSave.Click
        SaveTxRecommend()
    End Sub






    Private Sub SaveInvestigation()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertInvestigation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
        myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNInvestigation.Tables("dtInvestigation").Rows.Count
        If (count > 0) Then
            GV_SELECTED_INVESTID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
        End If

        myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
        myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
        myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
        myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.ExecuteNonQuery()
        MsgBox("Investigation records " + GV_SELECTED_INVESTID + " updated.")
        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing


    End Sub

    Private Sub SavePatientEvent()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent_btbPresent", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_id_old", SqlDbType.VarChar)
        myCommand.Parameters.Add("@orders", SqlDbType.VarChar)

        Dim selectedOrder As String = "99"
        If Not String.IsNullOrEmpty(presentOrder.Text) And presentOrder.Text <> "NULL" Then
            selectedOrder = presentOrder.Text
        End If


        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@Pt_id1").Value = ""
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(cbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(cbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(CboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(CboxMetasEvent.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@Event_id_old").Value = ""
        myCommand.Parameters("@orders").Value = selectedOrder

        myCommand.ExecuteNonQuery()

        MsgBox("Event records " + GV_SELECTED_EVENTID + " updated.")

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing

        'presentOrder.SelectedIndex = 39
        Dim NextFriday As Date = GetNext(DayOfWeek.Friday)
        ListPresentationPatients(Me.btbPresentDate.Value)
        'FrmDiagnosis.TreeView2.CollapseAll()
    End Sub


    Private Sub SavePatientHistory()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertHistory", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNHistory.Tables("dtHistory").Rows.Count
        If (count > 0) Then
            GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
        End If

        If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
        Else
            myCommand.Parameters("@History_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
        myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        MsgBox("Event records " + GV_SELECTED_EVENTID + " updated.")

        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
    End Sub


    Private Sub SaveHistology()

        Dim physicalnotes As String
        physicalnotes = txtPhysicalNotes.Text


        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistology", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
            myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
            myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
            myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
            myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_2", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
            myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            'myCommand.Parameters.Add("@side", SqlDbType.VarChar)

            Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
            Dim count As Integer = Me.DSNHistology.Tables("dtHistology").Rows.Count
            If (count > 0) Then
                GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            End If

            If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then
                gv_isedit = False
            Else
                gv_isedit = True
            End If

            If gv_isedit = True Then
                myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            Else
                myCommand.Parameters("@Histo_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID

            'If Not IsNumeric(txtTumourSize.Text) Then
            'Me.ErrorProvider1.SetError(Me.txtTumourSize, "Please Enter numeric values for tumor size")
            'Throw New Exception("Please enter a numeric value")
            'Else
            'myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            'End If
            myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
            myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
            myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
            myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
            myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
            myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
            myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
            myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
            myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
            myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
            myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
            myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
            myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
            myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
            myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
            myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
            myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
            myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
            myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
            myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
            myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
            myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
            myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
            myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
            myCommand.Parameters("@SLN_2").Value = Trim(cbxSentinelLNPolarity.Text)
            myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
            myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
            myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
            myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
            myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
            myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
            myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
            myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            'myCommand.Parameters("@side").Value = Trim(cbxSide.Text)

            myCommand.ExecuteNonQuery()
            MsgBox("Event records " + GV_SELECTED_EVENTID + " updated.")
            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub SaveTxRecommend()
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertTxRecommendation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
        myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
        myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
        myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)


        Dim currentSelectedEvent As String = GV_SELECTED_EVENTID
        Dim count As Integer = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
        If (count > 0) Then
            GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
        End If

        If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then
            gv_isedit = False
        Else
            gv_isedit = True
        End If

        If gv_isedit = True Then
            myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
        Else
            myCommand.Parameters("@recom_id").Value = "0"
        End If
        myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
        myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
        myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
        myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
        myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
        myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
        myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
        myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
        myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.ExecuteNonQuery()
        MsgBox("Investigation records " + GV_SELECTED_INVESTID + " updated.")
        'myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing
    End Sub

    Dim entryModeEntered As Boolean = False


    Private Sub cboxMarginDCIS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboxMarginDCIS.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub CboxMeta_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboxMeta.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub CboxMetasEvent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboxMetasEvent.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxBone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxBone.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxCaseType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxCaseType.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxClinAxillaryLN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxClinAxillaryLN.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxCT_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxCT.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxcT_Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxcT_Status.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxCXR_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxCXR.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxDCIS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxDCIS.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxDoctor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxDoctor.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxER_Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxER_Status.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxErbB2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxErbB2.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxExtChestWall_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxExtChestWall.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxHistoDx_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxHistoDx.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxHistoGrade_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxHistoGrade.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxHistory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxHistory.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxHistoType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxHistoType.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxLaterality_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxLaterality.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxLymhovascular_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxLymhovascular.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxM_Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxM_Status.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxMargin_invasive_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxMargin_invasive.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxN_Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxN_Status.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxPR_Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxPR_Status.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxradialMargin_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxradialMargin.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxReconstruction_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxReconstruction.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxSentinel_LN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSentinel_LN.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxSentinelLNPolarity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSentinelLNPolarity.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxSide_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSide.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxStatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxStatus.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxTypeBiopsy_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxTypeBiopsy.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub
    Private Sub cbxTypeSurg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxTypeSurg.SelectedIndexChanged
        If Not is_on_loading Then
            Me.Button2.BackColor = Color.Green
            Me.is_on_loading = False
            Me.hasAnyUpdate = True
        End If
    End Sub




    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        saveAllRecords(GV_SELECTED_EVENTID)
        Me.hasAnyUpdate = False
        Me.Button2.BackColor = Color.Pink
        Me.Button2.Text = "Save All"
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.GLB_init = 0
        ListPresentationPatients(Me.btbPresentDate.Value)
    End Sub

    Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click
        If MessageBox.Show("Are you sur to DELETE this event?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Dim SqlConn As SqlConnection = New SqlConnection(GV_CONNETION)
            Dim myCommand As SqlCommand = New SqlCommand("update [Event] set [status] = 'D' where event_ID = '" + GV_SELECTED_EVENTID + "'", SqlConn)
            SqlConn.Open()
            myCommand.ExecuteNonQuery()
            SqlConn.Close()
        Else

        End If

        ListPresentationPatients(Me.btbPresentDate.Value)

    End Sub



    Dim vHisto_ID As String = ""
    Dim vHistoIDold As String = ""
    Dim vNeoAdj_ID As String = ""
    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        
        'validation to check if histology is already created, if no histology present for current event, prompt to save histo 1st

        Dim SqlConnection2 As New SqlConnection()
        SqlConnection2 = New SqlConnection(GV_CONNETION)
        If SqlConnection2.State = ConnectionState.Closed Then SqlConnection2.Open()
        Dim sqlCmd2 = New SqlCommand("select top 1 histo_id,histoIDold from histology where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection2)
        Try
            Dim objReader As SqlDataReader = sqlCmd2.ExecuteReader
            Do While objReader.Read
                vHisto_ID = IIf(IsDBNull(objReader("histo_id")), "", objReader("histo_id"))
                vHistoIDold = "S" + IIf(IsDBNull(objReader("histoIDold")), "", objReader("histoIDold"))
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd2.Cancel()
        SqlConnection2.Close()
        sqlCmd2 = Nothing
        SqlConnection2.Close()

        If (vHisto_ID = "") Then
            MsgBox("Please create an event or histology first.")
            Exit Sub
        End If

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select Neoadj_id from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vNeoAdj_ID = IIf(IsDBNull(objReader("Neoadj_id")), "", objReader("Neoadj_id"))
                GV_SELECTED_NEOADJID = vNeoAdj_ID
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

        If LTrim(RTrim(vNeoAdj_ID)) = "" Then
            'MsgBox("Please unlock event before creating new neoadjuvant details")
            'Else

            'GV_SELECTED_HISTOLOGYID =
            FrmNeoadjuvant.ShowDialog()

        Else
            FrmNeoadjuvant.ShowDialog()
        End If

    End Sub




    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        'validation to check if histology is already created, if no histology present for current event, prompt to save histo 1st
        Dim vHisto_ID As String = ""
        Dim SqlConnection2 As New SqlConnection()
        SqlConnection2 = New SqlConnection(GV_CONNETION)
        If SqlConnection2.State = ConnectionState.Closed Then SqlConnection2.Open()
        Dim sqlCmd2 = New SqlCommand("select histo_id from histology where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection2)
        Try
            Dim objReader As SqlDataReader = sqlCmd2.ExecuteReader
            Do While objReader.Read
                vHisto_ID = IIf(IsDBNull(objReader("histo_id")), "", objReader("histo_id"))
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd2.Cancel()
        SqlConnection2.Close()
        sqlCmd2 = Nothing
        SqlConnection2.Close()

        If (vHisto_ID = "") Then
            MsgBox("Please create an event or histology first.")
            Exit Sub
        End If

        'added by cherwei for validation such that a new prior treatment form cannot be saved if current event is locked
        'validation added by cherwei, if current event is locked, do not allow new neoadj treatments to be added
        Dim vNeoAdj_ID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select priortx_id from priortx where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vNeoAdj_ID = IIf(IsDBNull(objReader("priortx_id")), "", objReader("priortx_id"))
            Loop

        Catch ex As Exception
            'MsgBox(ex.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

        If LTrim(RTrim(vNeoAdj_ID)) = "" Then
            MsgBox("Please unlock event before creating new prior treatment record")
        Else
            FrmRcdPriorTreatment.ShowDialog()
        End If
    End Sub
End Class